package com.gxa.web_admin.controller.propertycontroller;

import com.gxa.common.R;
import com.gxa.modules.pojo.Guards;
import com.gxa.modules.pojo.GuardsAlarm;
import com.gxa.modules.service.propertyservice.EquipmentService;
import com.gxa.modules.service.propertyservice.VisitorRegisterService;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @version 1.0
 * @Author fluoxetine
 * @Date 2022/4/30 23:57
 **/
@RestController
@RequestMapping("/Equipment/Intelligent")
@Api(value = "智能门禁管理",tags = "门禁设备查询接口API")
@RequiresPermissions("门禁管理")
public class EquipmentController {


    @Autowired
    private EquipmentService equipmentService;

    @GetMapping(value = "/selectGuards")
    @ApiOperation(value = "门禁设备查询接口" ,notes = "提供当前页码数与每页显示条数",httpMethod = "GET",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "当前页码数",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "size",value = "每页显示条数", required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "deviceName",value = "根据设备名称查询", required = false,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "deviceId",value = "根据设备编号查询", required = false,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "guardsType",value = "每页显示条数", required = false,dataType = "String",paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功"),
            @ApiResponse(code = 400,message = "参数格式不对"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    public R selectGuards(@RequestParam int page,
                          @RequestParam int size,
                          String deviceName,String deviceId,String guardsType)
    {
        return  equipmentService.selectGuards(page,size,deviceName,deviceId,guardsType);
    }

    @GetMapping("/selectGuardsById")
    @ApiOperation(value = "门禁设备查询接口" ,notes = "提供当前页码数与每页显示条数",httpMethod = "GET",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "根据id详细查询门禁设备",required = true,dataType = "int",paramType = "query"),
    })
    public R selectGuardsById(@RequestParam int id)
    {
        return equipmentService.selectGuardsById(id);
    }

    @PostMapping("/addGuards")
    @ApiOperation(value = "添加门禁设备接口" ,notes = "提供当前页码数与每页显示条数",httpMethod = "POST",response = R.class)
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功"),
            @ApiResponse(code = 400,message = "参数格式不对"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    public R addGuards(@RequestBody Guards guards)
    {
        return equipmentService.addGuards(guards);
    }

    @PostMapping(value = "/updateGuardsType")
    @ApiOperation(value = "修改门禁设备状态", notes = "提供当前页码数与每页显示条数", httpMethod = "POST", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键id", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "GuardsTypeId", value = "设备状态", required = true, dataType = "int", paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "请求成功"),
            @ApiResponse(code = 404, message = "找不到页面"),
            @ApiResponse(code = 500, message = "后台服务器错误")
    })
    public R updateGuardsType(@RequestParam int  GuardsTypeId,
                              @RequestParam int id) {
        return equipmentService.updateGuardsType(GuardsTypeId,id);
    }

    @PostMapping("/deleteGuardsById")
    @ApiOperation(value = "删除门禁设备接口" ,notes = "提供当前页码数与每页显示条数",httpMethod = "POST",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "根据此条件查询设备信息",required = true,dataType = "String",paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功"),
            @ApiResponse(code = 400,message = "参数格式不对"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    public R deleteGuardsById(String id)
    {
        return equipmentService.deleteGuardsById(id);
    }


    /**
     * 删除
     */
    @PostMapping("/batchDelete")
    @ApiOperation(value = "批量删除访客接口" ,notes = "提供当前页码数与每页显示条数",httpMethod = "POST",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "gpId",value = "批量删除访客信息",required = true,dataType = "String",paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功"),
            @ApiResponse(code = 400,message = "参数格式不对"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    public void batchDelete(@RequestParam(value = "gpId") String gpId) {
        String[] gpIds = gpId.split(",");
        List<Integer> list = new ArrayList<>();
        for(String str:gpIds){
            list.add(Integer.parseInt(str));
        }
        equipmentService.batchDelete(list);
    }


    @GetMapping("/selectGuards_alarm")
    @ApiOperation(value = "查询门禁报警接口" ,notes = "提供当前页码数与每页显示条数",httpMethod = "GET",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "当前页码数",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "size",value = "每页显示条数", required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "deviceName",value = "根据设备名称查询", required = false,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "deviceId",value = "根据设备编号查询", required = false,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "guardsAlarmType",value = "根据设备状态查询", required = false,dataType = "String",paramType = "query")

    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功"),
            @ApiResponse(code = 400,message = "参数格式不对"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    public R selectGuards_alarm(@RequestParam int page,
                                @RequestParam int size,
                                String deviceName,String deviceId,String guardsAlarmType)
    {
        return  equipmentService.selectGuards_alarm(page,size,deviceName,deviceId,guardsAlarmType);
    }

    @GetMapping("/selectGuardsAlarmById")
    @ApiOperation(value = "门禁报警设备查询接口" ,notes = "提供当前页码数与每页显示条数",httpMethod = "GET",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "根据id详细查询门禁设备",required = true,dataType = "int",paramType = "query"),
    })
    public R selectGuardsAlarmById(@RequestParam int id)
    {
        return equipmentService.selectGuardsAlarmById(id);
    }

    @PostMapping("/deleteGuards_alarmById")
    @ApiOperation(value = "删除门禁报警接口" ,notes = "提供当前页码数与每页显示条数",httpMethod = "POST",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "根据此条件查询设备信息",required = true,dataType = "String",paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功"),
            @ApiResponse(code = 400,message = "参数格式不对"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    public R deleteGuards_alarmById(String id)
    {
        return equipmentService.deleteGuards_alarmById(id);
    }



    @GetMapping("/selectGuards_patrol")
    @ApiOperation(value = "查询门禁巡查接口" ,notes = "提供当前页码数与每页显示条数",httpMethod = "GET",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "当前页码数",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "size",value = "每页显示条数",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "deviceName",value = "根据设备名字查询",required = false,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "deviceId",value = "根据设备编号查询",required = false,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "patrolType",value = "根据设备状态查询", required = false,dataType = "String",paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功"),
            @ApiResponse(code = 400,message = "参数格式不对"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    public R selectGuards_patrol(@RequestParam int page,
                                 @RequestParam int size,
                                 String deviceName,String deviceId,String patrolType)
    {
        return  equipmentService.selectGuards_patrol(page,size,deviceName,deviceId,patrolType);
    }

    @GetMapping("/selectGuardsPatrolById")
    @ApiOperation(value = "门禁巡视设备查询接口" ,notes = "提供当前页码数与每页显示条数",httpMethod = "GET",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "根据id详细查询门禁巡视",required = true,dataType = "int",paramType = "query"),
    })
    public R selectGuardsPatrolById(@RequestParam int id)
    {
        return equipmentService.selectGuardsPatrolById(id);
    }

    @PostMapping("/deleteGuards_patrolById")
    @ApiOperation(value = "删除门禁运维接口" ,notes = "提供当前页码数与每页显示条数",httpMethod = "POST",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "根据此条件查询设备信息",required = true,dataType = "String",paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功"),
            @ApiResponse(code = 400,message = "参数格式不对"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    public R deleteGuards_patrolById(String id)
    {
        return equipmentService.deleteGuards_patrolById(id);
    }

}
